﻿<Menu SelectedKeys="new string[1] { Runtime }">
    <MenuItem Key="Server" OnClick="SwithServer">
        <a>
            Server
        </a>
    </MenuItem>
    <MenuItem Key="Wasm" OnClick="SwithWasm">
        <a>
            Wasm
        </a>
    </MenuItem>
</Menu>

@code{
    private string Runtime
    {
        get
        {
            var runtime = System.Runtime.InteropServices.RuntimeInformation.RuntimeIdentifier;
            if(runtime == "browser-wasm")
            {
                return "Wasm";
            }
            else
            {
                return "Server";
            }
        }
    }

    [Inject]
    IJSRuntime JSRuntime{ get; set; }
    [Inject]
    NavigationManager NavigationManager{ get; set; }
    [Inject]
    UserConfig UserConfig{ get; set; }

    private void SwithWasm()
    {
        if (!Config.IsServer) return;
        var iframeMessage = new IframeMessage();
        iframeMessage.Pattern = Pattern.Wasm;
        iframeMessage.Url = NavigationManager.Uri;
        _ = JSRuntime.InvokeVoidAsync("iframeMessage", iframeMessage);
    }

    private void SwithServer()
    {
        if (Config.IsServer) return;
        _ = JSRuntime.InvokeVoidAsync("switch_server", NavigationManager.Uri);
    }
}